package com.szl.yeb.controller;


import com.szl.yeb.common.constant.MsgConstant;
import com.szl.yeb.entity.Department;
import com.szl.yeb.common.R;
import com.szl.yeb.service.DepartmentService;
import com.szl.yeb.utils.ResponseProcessor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * (Department)表控制层
 *
 * @author szl
 * @since 2022-08-24 16:21:23
 */
@Api(tags = "部门管理接口(DepartmentController)")
@RestController
@RequestMapping("/system/basic/dept")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @ApiOperation("查询所有部门及其子部门")
    @GetMapping("/")
    public R<Object> getDepartmentsWithChildren(){
        return R.obj(departmentService.getDepartmentsWithChildren());
    }

    @ApiOperation("添加部门")
    @PostMapping("/")
    public R<Object> addDepartment(@RequestBody Department department){
        return ResponseProcessor.getResWithMsg(departmentService.addDepartment(department), MsgConstant.ADD);
    }

    @ApiOperation("删除部门")
    @DeleteMapping("/{id}")
    public R<Object> deleteDepartment(@PathVariable("id") Integer did){
        return ResponseProcessor.getResWithMsg(departmentService.deleteDepartment(did), MsgConstant.DELETE);
    }
}

